{-# OPTIONS_HADDOCK prune, ignore-exports #-}
module Main where

import IO

import Data.Char
import Data.List
import qualified Data.Map as Map

import Text.ParserCombinators.Parsec.Prim

import TIChecker  
import TIParser   
import TITypes  
import Combinators  


runInterpreterCycle :: IO ()
runInterpreterCycle = do putStr "> "
                         term <- getLine
                         if (map toUpper term) `isPrefixOf` ":QUIT"
                           then return ()
                           else do case parse parseExpr "" (trimSpaces term) of
                                     Left msg -> putStrLn (show msg ++ "\n")
                                     Right r  -> case inferType r generateTyVarNames Map.empty of
                                                   Left msg     -> putStrLn (msg ++ "\n")
                                                   Right (e, _) -> let Just t = Map.lookup r e
                                                                   in  putStrLn (show r ++ " :: " ++ show t ++ "\n")
                                   runInterpreterCycle

trimSpaces :: String  -> String  
trimSpaces = filter (not . isSpace)


main :: IO ()  
main = do hSetBuffering stdout NoBuffering
          putStrLn "Type checker for simple Lambda-calculus. Version 0.1.\nEnter lambda-term for typing or \":quit\" to quit.\n"
          runInterpreterCycle


